package com.fit.spring.boot.proxy.interceptor.extension;

import org.aopalliance.intercept.MethodInterceptor;

/**
 * 拦截器配置接口
 * @author hcl
 *
 */
public abstract class InterceptorConfiguration {
	
	
	/**
	 * 拦截器
	 */
	private MethodInterceptor methodInterceptor;
	
	/**
	 * 获取拦截器
	 * @return
	 */
	public final MethodInterceptor getMethodInterceptor(){
		if(methodInterceptor == null){
			methodInterceptor = registeredInterceptor();
			if(methodInterceptor == null){
				throw new RuntimeException("拦截器注册方法 " + this.getClass().getName() + ".registeredInterceptor() 返回的是一个null, 这里必须返回一个MethodInterceptor实例。");
			}
		}
		return methodInterceptor;
	}
	
	/**
	 * 注册拦截器
	 * @return
	 */
	public abstract MethodInterceptor registeredInterceptor();
	

	/**
	 * 是否拦截当前方法
	 * 如果返回true可以再Config中添加方法参数
	 * @param config
	 */
	public abstract boolean isMethodInterceptor(Config config);
	
}
